<template>
  <div class="container">
    <div class="login-wrapper">
      <div class="avatar-container animate-zoom">
        <img src="/src/assets/avatar.jpg" alt="头像" class="avatar" />
      </div>
      <div class="input-group animate-fade" style="animation-delay: 0.3s;">
        <div class="input-label">账号:</div>
        <van-field v-model="account" class="custom-field" />
      </div>
      <div class="input-group animate-fade" style="animation-delay: 0.5s;">
        <div class="input-label">学号:</div>
        <van-field v-model="studentId" class="custom-field" />
      </div>
      <div class="input-group animate-fade" style="animation-delay: 0.7s;">
        <div class="input-label">密码:</div>
        <van-field v-model="password" type="password" class="custom-field" />
      </div>
      <div class="register-link animate-fade" style="animation-delay: 0.2s;" @click="goToLogin()">返回</div>
      <div class="login-button animate-fade" style="animation-delay: 0.9s;">
        <van-button class="login-btn" @click="register()">注册</van-button>
      </div>
      <div class="footer animate-fly-up">
        <div class="footer-subtitle">维护预约中心</div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { Field as VanField, Button as VanButton } from 'vant'

const router = useRouter()
const account = ref('')
const studentId = ref('')
const password = ref('')

const goToLogin = () => {
  router.push('/login')
}

const register = () => {
  if (account.value.trim() === '') {
    alert('账号不能为空')
    return
  }
  
  if (studentId.value.trim() === '') {
    alert('学号不能为空')
    return
  }
  
  alert('注册成功')
  
  setTimeout(() => {
    router.go(-1)
  }, 1500)
}
</script>

<style scoped>
.container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: linear-gradient(180deg, rgba(195, 207, 226, 1) 0%, rgba(245, 247, 250, 1) 100%);
}

.login-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 400px;
}

.avatar-container {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  overflow: hidden;
  margin-bottom: 60px;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.5);
}

.animate-zoom {
  animation: zoomIn 0.5s ease-out forwards;
}

@keyframes zoomIn {
  0% {
    transform: scale(0.2);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.input-group {
  display: flex;
  align-items: center;
  width: 336px;
  margin-bottom: 24px;
}

.input-label {
  font-size: 16px;
  font-weight: bold; 
  color: #333;
  margin-right: 10px;
  white-space: nowrap;
}

.custom-field {
  flex-grow: 1;
  background-color: #ffffff;
  border-radius: 10px;
  padding: 8px 12px;
}

.custom-field :deep(.van-field__control) {
  color: #333;
  text-align: left;
}

.custom-field :deep(.van-field__placeholder) {
  color: #999;
  text-align: left;
}

.register-link {
  position: absolute;
  top: 20px;
  left: 20px; 
  font-size: 14px;
  color: #3a3939;
  cursor: pointer;
  margin: 10px 30px 0 0;
}

.login-button {
  margin-top: 25px;
  width: 336px;
}

.login-btn {
  width: 100%;
  height: 45px;
  font-weight: bold;
  border-radius: 25px;
  background: #e2e2e2;
  border: none;
  color: black;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.5);
  transition: all 0.3s ease;
}

.login-btn:active {
  background: #bfbebe;
  transform: translateY(2px);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.4);
}

.footer {
  text-align: center;
  margin-top: 40px;
}

.animate-fly-up {
  animation: flyUp 0.5s ease-out forwards;
}

@keyframes flyUp {
  0% {
    transform: translateY(50px);
    opacity: 0;
  }
  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

.footer-title {
  font-size: 18px;
  font-weight: bold;
  color: #333;
}

.footer-subtitle {
  font-size: 14px;
  color: #666;
}

.animate-fade {
  animation: fadeIn 0.8s ease-out forwards;
  opacity: 0;
}

@keyframes fadeIn {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}

</style>